from django.db import models

# Create your models here.


class UserInfo(models.Model):
    """"""
    """用户信息表"""
    name = models.CharField(verbose_name="名称", max_length=32)
    password = models.CharField(verbose_name="密码", max_length=64)
    phone_number = models.CharField(verbose_name="电话号码", max_length=11)
    user_address = models.CharField(verbose_name='住址', max_length=256)
    gender_choices = (
        (1, '男'),
        (2, '女'),
        (3, "未选")
    )
    gender = models.SmallIntegerField(verbose_name="性别", choices=gender_choices, default=3)
    level_choices = (
        (1, "用户"),
        (2, "冻结"),
        (3, "管理员"),
    )
    level = models.SmallIntegerField(verbose_name="身份", choices=level_choices, default=1)
    email = models.CharField(verbose_name="邮箱", max_length=32)
    is_active_choices = (
        (1, "已激活"),
        (0, "未激活")
    )
    is_active = models.SmallIntegerField(verbose_name="激活状态", choices=is_active_choices, default=0)

    def __str__(self):
        return self.name



class Address(models.Model):
    """"""
    """收货地址信息"""
    user = models.ForeignKey(verbose_name="所属账户", to="UserInfo", to_field="id", on_delete=models.CASCADE)
    receiver = models.CharField(verbose_name="收件人",max_length=32)
    address = models.CharField(verbose_name="收货地址", max_length=256)
    postal_code = models.CharField(verbose_name="邮政编码", max_length=6)
    phone = models.CharField(verbose_name="联系电话", max_length=11)
    is_default = models.BooleanField(verbose_name="是否默认", default=False)






class Category(models.Model):
    """"""
    """商品分类"""
    title = models.CharField(verbose_name="商品种类", max_length=256)

    def __str__(self):
        return self.title


class Goods(models.Model):
    """"""
    """商品表"""
    title = models.CharField(verbose_name="商品名称", max_length=256)
    price = models.DecimalField(verbose_name="价格",max_digits=10, decimal_places=2, default=0)
    inventory = models.IntegerField(verbose_name="库存")
    sales = models.IntegerField(verbose_name="销量", default=0)
    introduction = models.CharField(verbose_name="简介", max_length=256, default='')
    address = models.CharField(verbose_name="发货地址", max_length=256)
    phone = models.CharField(verbose_name="联系电话", max_length=11)
    category = models.ForeignKey(verbose_name="商品种类", to="Category", to_field="id", on_delete=models.CASCADE)
    img = models.FileField(verbose_name="商品照片", max_length=128, upload_to='goods_img/')
    status_choices = (
        (1, "上架"),
        (2, '下架')
    )
    status = models.SmallIntegerField(verbose_name="商品状态", choices=status_choices, default=1)
    recommendation = models.BooleanField(verbose_name="推荐", default=False)



class Order(models.Model):
    """"""
    """订单表"""
    oid = models.CharField(verbose_name="订单号", max_length=64)
    good = models.ForeignKey(verbose_name="商品", to="Goods", to_field="id", on_delete=models.CASCADE)
    purchaser = models.ForeignKey(verbose_name="用户", to="UserInfo", to_field="id", on_delete=models.CASCADE)
    consignee_info = models.ForeignKey(verbose_name="收货人信息", to="Address", to_field="id", on_delete=models.CASCADE)
    number = models.IntegerField(verbose_name="数量")
    price = models.DecimalField(verbose_name="价格",max_digits=10, decimal_places=2, default=0)
    creat_time = models.DateField(verbose_name="创立时间")
    order_status_choices = (
        (1, "未支付"),
        (2, '已支付'),
        (3, '准备发货'),
        (4, '已发货'),
        (5, '待收货'),
        (6, '已收货'),
    )
    order_status = models.SmallIntegerField(verbose_name="订单状态", choices=order_status_choices, default=1)


class goods_slide_show(models.Model):
    """"""
    """首页商品轮播展示表"""
    goods = models.ForeignKey(verbose_name="商品", to="Goods", to_field="id", on_delete=models.CASCADE)



class goods_type_show(models.Model):
    """"""
    """首页分类商品展示"""

    goods_type = models.ForeignKey(verbose_name="商品种类", to="Category", to_field="id", on_delete=models.CASCADE)
    goods = models.ForeignKey(verbose_name="商品", to="Goods", to_field="id", on_delete=models.CASCADE)





class Shopping_Cart(models.Model):
    """"""
    """购物车类"""

    goods = models.ForeignKey(verbose_name="商品", to="Goods", to_field="id", on_delete=models.CASCADE)
    user = models.ForeignKey(verbose_name="用户", to="UserInfo", to_field="id", on_delete=models.CASCADE)
    goods_num = models.IntegerField(verbose_name="数量")
    total = models.DecimalField(verbose_name="价格",max_digits=10, decimal_places=2, default=0)






class new_product(models.Model):
    """"""
    """新品推荐"""

    goods = models.ForeignKey(verbose_name="新品", to="Goods", to_field="id", on_delete=models.CASCADE)

class goods_details(models.Model):
    """"""
    """商品介绍"""

    goods = models.ForeignKey(verbose_name="商品", to="Goods", to_field="id", on_delete=models.CASCADE)
    details = models.TextField(verbose_name="介绍")


class CommentInfo(models.Model):
    """"""
    """评论表"""
    goods = models.ForeignKey(verbose_name="商品", to="Goods", to_field="id", on_delete=models.CASCADE)
    user = models.ForeignKey(verbose_name="用户", to="UserInfo", to_field="id", on_delete=models.CASCADE)
    create_time = models.DateField(verbose_name="评论时间")
    content = models.TextField(verbose_name="评论", max_length=256)


class sales_data(models.Model):
    """"""
    """销售数据表"""
    date = models.DateField(verbose_name="创立时间")
    num = models.IntegerField(verbose_name="数量")
    sales = models.IntegerField(verbose_name="销量")
    category = models.ForeignKey(verbose_name="商品种类", to="Category", to_field="id", on_delete=models.CASCADE)
